<?php

    session_start();
//    echo "Login: ".$_SESSION["userID"]." ".$_SESSION["userType"];

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

    if(isset($_SESSION["userID"]) && !strcmp($_SESSION["userType"], "manager")){

    $categoryName = $_GET["categoryName"];
    
    $con = mysql_connect("localhost", "zhouzhao", "19831022");
    if(!$con){
        die("could not connect to DB: ".mysql_error());
    }
    
    mysql_selectdb("cloudcom", $con);
    
    $sql = "select * from categories";
    
    if(strlen($categoryName) != 0){
        $sql = $sql." where categoryName='$categoryName'";
    }
    
    $result = mysql_query($sql);
    
    echo "query: $sql";
    echo "<table border='1' id='categoryTable'>
        <tr>
            <th>CategoryID</th>
            <th>Category name</th>
            <th>Category description</th>
        </tr>";

    while($row = mysql_fetch_assoc($result)){
        echo "<tr>";
        echo "<td>".$row["categoryID"]."</td>";
        echo "<td>".$row["categoryName"]."</td>";
        echo "<td>".$row["categoryDescription"]."</td>";
        echo "</tr>";
    }
    echo "</table>";    
    }else{
        require 'login.html';
    }
?>
